<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no" />
	<title>首页</title>
	<link rel="stylesheet" type="text/css" href="../c/aui.css" />
	<style>
		body {
			background-color: transparent;
			/*background-color: #000;*/
		}

		.t {
			background: #222;
			padding: 0.75rem;
		}

		.t .l {
			font-size: 1.2rem;
			text-align: center;
		}

		.t .l b {
			font-size: 0.75rem;
			padding-left: 1rem;
			color: #fff;
			font-weight: 300
		}

		.t .r {
			font-size: 0.75rem;
			opacity: 0.5;
			padding-top: 0.5rem;
			text-align: center;
		}

		.f {
			/*background: #222;*/
			color: #fff;
			margin-top: 0.5rem;
		}

		.f .l {
			/*width: 70%;*/
		}

		.f .l .title {
			color: #fff;
			font-weight: bold;
			font-size: 0.85rem;
			display: flex;
			justify-content: space-between;
			align-items: center;
			letter-spacing: 2px
		}

		.f .l .title span {}

		.f .l .title span:first-child {
			/*padding-right: 0.5rem;*/
		}

		.f .l .title span:last-child {
			/*color: #FE2C55*/
		}

		.f .l .p {
			font-size: 0.65rem;
			opacity: 0.6;
			color: #fff;
			padding-top: 0.25rem;
			letter-spacing: 1px
		}

		.f .r {
			background: #FE2C55;
			color: #fff;
			padding: 0.25rem 0.75rem;
			border-radius: 0.25rem;
		}

		.f .aui-card-list-footer {
			margin-bottom: 0.75rem;
		}

		.f .money {
			font-size: 0.9rem;
			color: #FE2C55;
			font-weight: bold;
			text-align: right;
			width: 3rem;
			letter-spacing: 1px;
		}

		.b {
			text-align: center;
			/*border-bottom: 3px solid #333;*/
			padding: 0.75rem 0;
			padding-bottom: 0.25rem;
			background: #222;
		}

		.b p {
			font-size: 0.65rem;
			padding-top: 0.35rem;
			opacity: 0.7;
			/*padding-bottom: 1rem;*/
		}
		.b .aui-row div{
			margin: 0.5rem 0;
		}
		.b .aui-row div img {
			width: 1.5rem;
			margin: 0 auto;
			opacity: 0.7;
		}

		.b .title {
			text-align: left;
			padding-left: 0.75rem;
			font-size: 0.75rem;
			padding-bottom: 0.25rem;
			opacity: 0.9;
		}
	</style>
</head>

<body>
	<div class="aui-content">
		<div class="t">
			<div class="l" style="color: #FE2C55;"></div>
			<div class="r"></div>
		</div>
		<div class="b">
			<div class="title">VIP特权</div>
			<div class="aui-row">
				<div class="aui-col-xs-4">
					<img src="../i/vip/vip.png" />
					<p>尊贵标志</p>
				</div>
				<div class="aui-col-xs-4">
					<img src="../i/vip/ad.png" />
					<p>去掉广告</p>
				</div>
				<div class="aui-col-xs-4">
					<img src="../i/vip/fabu.png" />
					<p>无限发布</p>
				</div>
				<div class="aui-col-xs-4">
					<img src="../i/vip/zhibo.png" />
					<p>开直播</p>
				</div>
				<div class="aui-col-xs-4">
					<img src="../i/vip/video.png" />
					<p>付费视频</p>
				</div>
				<div class="aui-col-xs-4">
					<img src="../i/vip/jinbi.png" />
					<p id="jinbi">金币2倍</p>
				</div>
			</div>
		</div>
		<script id="sx-list" type="text/x-dot-template">
			{{ for(var i=0,len=it.length; i
			< len; i++) { }} <div class="aui-card-list-footer">
				<div class="l">
					<div class="title"><span>{{= it[i].time ? it[i].time+'天' : '永久'}}</span></div>
					<div class="p">{{? it[i].time }}有效期{{= it[i].time}}天会员服务{{??}}终身永久会员服务{{?}}</div>
				</div>
				<div class="money"><span>{{= it[i].money}}元</span></div>
				<div class="r" tapmode onclick="pay({{= it[i].money}},{{= it[i].id}},{{= it[i].time}})">
					<div>购买</div>
				</div>
	</div>
	{{ } }}
	</script>
	<div class="f" id="sx-view">
		<div id="loadingdi_huifu"><img src="../i/footer_progress.png" /></div>
	</div>
	</div>
</body>

<script type="text/javascript" src="../j/api.js"></script>
<script type="text/javascript">
	apiready = function() {
		_user = _getPrefs('_user');
		// beecloud = api.require('beecloud');
		_data()
		lists();
	}

	function _data() {
		if (_getPrefs('_user').vip) {
			$('.t .r').html('到期时间：<span>' + _getPrefs('_user').vip_time + '</span>');
			$('.t .l').html('VIP会员<b>剩余' + _getPrefs('_user').vip_d + '天</b>');
		} else {
			if (_user.vip_time) {
				$('.t .l').html('普通用户<b>已到期' + _getPrefs('_user').vip_d + '天</b>');
				$('.t .r').html('会员已到期：<span>' + _getPrefs('_user').vip_time + '</span>');
			} else {
				$('.t .l').html('普通用户');
				$('.t .r').html('未开通VIP会员');
			}
		}
	}

	function lists() {
		_ajax('member/vip_money', function(ret, err) {
			if (ret) {
				var evalData = doT.template($api.html($api.byId('sx-list')));
				$api.html($api.byId('sx-view'), evalData(ret));
				api.parseTapmode();
			} else {
				_alert('价格获取失败，请联系客服');
			}
		})
	}

	function pay(money, id, time) {
		if(_getPrefs('_config').pay.alipay == 1 && _getPrefs('_config').pay.weixin == 1){
			var buttons = ['支付宝', '微信'];
			var channel = ['ALI_APP','WX_APP'];
		}else if(_getPrefs('_config').pay.alipay == 1){
			var buttons = ['支付宝'];
			var channel = ['ALI_APP']
		}else if(_getPrefs('_config').pay.weixin == 1){
			var buttons = ['微信'];
			var channel = ['WX_APP']
		}else{
			return _msg('支付未开放，敬请期待！');
		}
		api.actionSheet({
			title: '选择支付方式',
			cancelTitle: '取消',
			buttons: buttons
		}, function(ret, err) {
			var index = ret.buttonIndex;
			var data = {};
			data.money = money * 100;
			data.type = 2;
			data.vip_pay_id = id;
			data.time = time;
			if(channel.length+1 == index){
				return _msg('支付取消');
			}
			data.channel = channel[index-1];
			_pay(data);
		});
	}

	function pays(data) {
		return _msg('支付未开通配置 请在后台支付配置！');
		_loading('正在请求')
		_ajax('member/pay_code', function(ret, err) {
			//	console.log(JSON.stringify(ret) + JSON.stringify(err))
			_loadingCloes()
			if (ret) {
				if (ret.ret) {
					// 判断结束
					var payData = {
						title: '用户(ID' + _user.id + ')购买' + data.time + '天VIP特权',
						totalfee: data.money,
						billno: ret.ret,
						channel: data.channel,
						optional: {
							uid: _user.id,
							payname: '购买VIP',
							type: data.type,
							vip_pay_id: data.vip_pay_id
						}
					};
					beecloud.pay(payData, payCallBack);

					function payCallBack(ret, err) {
						_heibai();
						if (ret) {
							if (ret.result_code == 0) {
								if (ret.result_msg == '支付成功') {
									_loading();
									_ajax('member/info', function(ret, err) {
										_loadingCloes();
										if (ret) {
											_setPrefs('_user', ret);
										}
										_data();
										return _alert('恭喜成功购买' + data.time + '天VIP特权')
									})

								}
							}else if (ret.errMsg) {
								_alert(JSON.stringify(ret))
							} else {
								_msg(ret.result_msg)
							}
						} else {
							_alert(JSON.stringify(err))
						}
					}
				} else {
					_alert('ret.err:' + ret.err)
				}
			} else {
				_alert(JSON.stringify(err))
			}
		}, data)
	}
</script>

</html>
